package com.example.android_contentprovider;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DbOpenHelper extends SQLiteOpenHelper {

    public DbOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory,
                        int version) {
        super(context, name, factory, version);
    }

    private static DbOpenHelper helper;
    public static synchronized DbOpenHelper getInstance(Context context) {
        if (helper == null) {
            //创建数据库
            helper = new DbOpenHelper(context, "my_provider.db", null, 1);
        }
        return helper;
    }

    //创建表
    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "create table person (_id integer primary key autoincrement, name Text, age integer)";
        db.execSQL(sql);
    }

    //数据库升级时，回调该方法
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

}
